# 进程池：非阻塞
"""

特点：添加一个执行一个任务，一个任务不结束，另外一个任务就进不来


"""
import os
from multiprocessing import Pool
import time
from random import random


# 阻塞式进程
def task(task_name):
    print("开始做任务了->", task_name)
    start = time.time()
    # 使用sleep
    time.sleep(random() * 2)
    end = time.time()
    print("完成任务：{}，总耗时：{}，进程ID：{}".format(task_name, (end - start), os.getpid()))


if __name__ == '__main__':
    # 创建池子
    pool = Pool(5)
    tasks = ["听音乐", "吃饭", "打游戏", "跑步", "看孩子", "散步", "做饭"]
    for tk in tasks:
        pool.apply(task, args=(tk,))
    print("over.......")
